package im.xz.cn.xiacore.menu.mainMenu;

import net.md_5.bungee.api.chat.hover.content.Item;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.util.ArrayList;
import im.xz.cn.xiacore.methods.playerHead;
import im.xz.cn.xiacore.methods.rank;
import im.xz.cn.xiacore.methods.itemStack;

public class menu implements CommandExecutor {
    @Override
    public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {

        try {
            if (commandSender instanceof Player) {
                Player player = (Player) commandSender;
                ItemStack introduce = new ItemStack(Material.PAPER);
                ItemMeta introduce_meta = introduce.getItemMeta();
                introduce_meta.setDisplayName(ChatColor.RED + "繁星梦服务器介绍");
                ItemStack forNormal = itemStack.createItemStack(Material.PAPER,ChatColor.AQUA + "normal服务器快捷操作栏",ChatColor.WHITE + "右侧各个快捷方式将有不同的效果，可点击使用","","",1,true);
                ItemStack kill = itemStack.createItemStack(Material.REDSTONE,ChatColor.RED + "点此以杀死自己",ChatColor.WHITE + "这将使系统杀死你，或许可以帮助你快",ChatColor.WHITE + "捷回到出生点。请谨慎使用。","",1,false);
                ItemStack weather = itemStack.createItemStack(Material.WATER_BUCKET,ChatColor.RED + "点此切换所在世界天气",ChatColor.WHITE + "这将改变所在世界天气，",ChatColor.WHITE + "请勿滥用,妨碍其他玩家游戏,否则您将被禁用","",1,false);
                ItemStack sun = itemStack.createItemStack(Material.SUNFLOWER,ChatColor.RED + "点此将世界时间设置为白昼",ChatColor.WHITE + "这将将时间设置为白昼",ChatColor.WHITE + "请勿滥用,妨碍其他玩家游戏,否则您将被禁用","",1,false);
                ItemStack noWar = itemStack.createItemStack(Material.WHITE_BANNER,ChatColor.GREEN + "开启免战",ChatColor.WHITE + "点击以切换免战状态。免战状态下，",ChatColor.WHITE + "你无法和玩家对战,其他玩家也无法伤害你。","",1,false);
                ArrayList<String> introduce_lore = new ArrayList<>();
                introduce_lore.add(ChatColor.WHITE + "1.这是一个多元的服务器");
                introduce_lore.add(ChatColor.WHITE + "2.你可使用正版/LittleSkin/繁星梦皮肤站进入游玩");
                introduce_lore.add(ChatColor.WHITE + "3.你可在forum.starsDream.top上报问题或交流");
                introduce_lore.add(ChatColor.WHITE + "4.请勿作弊，请友善游玩，玩的开心");
                ItemStack tpsBar = itemStack.createItemStack(Material.DIAMOND,ChatColor.RED + "开关服务器TPS和RAM监控板",ChatColor.WHITE + "点击显示/隐藏tps和ram监控板",ChatColor.GRAY + "tps/mspt值揭示服务器方面是否卡顿,Ping值揭示网络是否流畅",ChatColor.GRAY + "mspt≤50表示服务器优秀。",1,false);
                ItemStack miniGame = itemStack.createItemStack(Material.PAPER,ChatColor.AQUA + "小游戏",ChatColor.WHITE + "点击右边的选项游玩我们的小游戏吧！","","",1,false);
                ItemStack bedwar = itemStack.createItemStack(Material.LIGHT_BLUE_BED,ChatColor.RED + "游玩起床战争",ChatColor.WHITE + "点击以加入起床战争",ChatColor.WHITE + "邀请朋友们一起来玩吧！","",1,false);
                ItemStack zombies = itemStack.createItemStack(Material.ZOMBIE_HEAD,ChatColor.RED + "游玩僵尸末日",ChatColor.WHITE + "点击以加入僵尸末日！",ChatColor.WHITE + "邀请朋友们一起来玩吧！","",1,false);
                introduce_lore.add(ChatColor.WHITE + "");
                introduce_lore.add(ChatColor.GRAY + "如何查看服务器的各种网址，加入QQ群？");
                introduce_lore.add(ChatColor.GRAY + "你只需要关闭菜单，轻触键盘上的ESC，再点击");
                introduce_lore.add(ChatColor.GRAY + "“服务器链接”选项卡，然后它们将呈现在你眼前!");
                ItemStack hideAndSeek = itemStack.createItemStack(Material.PIG_SPAWN_EGG,ChatColor.RED + "游玩方块躲猫猫",ChatColor.WHITE + "点击以加入方块躲猫猫！",ChatColor.WHITE + "邀请朋友们一起来玩吧！","",1,false);
                ItemStack lobby = itemStack.createItemStack(Material.COMPASS,ChatColor.LIGHT_PURPLE + "返回大厅",ChatColor.WHITE + "点击返回大厅！",ChatColor.WHITE + "其实重进也可以返回哦！","",1,false);
                ItemStack normalIn = itemStack.createItemStack(Material.PAPER,ChatColor.AQUA + "生存服务器快捷选项",ChatColor.WHITE + "在右边选取生存玩法！","","",1,false);
                introduce_meta.setEnchantmentGlintOverride(true);
                introduce_meta.setLore(introduce_lore);
                introduce.setItemMeta(introduce_meta);
                ItemStack normal = itemStack.createItemStack(Material.GRASS_BLOCK,ChatColor.RED + "normal服务器",ChatColor.WHITE + "基本的生存服务器！",ChatColor.WHITE + "不限制红石等！但请勿影响其他玩家游戏",ChatColor.WHITE + "请在游玩红石时开始TPS和RAM栏，当服务器无法承受时请及时调整",1,false);
                ItemStack randomTP = itemStack.createItemStack(Material.CORNFLOWER,ChatColor.RED + "随机传送",ChatColor.WHITE + "点击以随机传送到世界上的任意位置","","",1,false);
                ItemStack mod = itemStack.createItemStack(Material.ANVIL,ChatColor.RED + "模组服务器",ChatColor.WHITE + "点击游玩模组生存服务器",ChatColor.WHITE + "你需要安装相应模组，详细请访问论坛了解",ChatColor.WHITE + "注意:mod服务器无法打开菜单,请输入/lobby回到大厅",1,false);
                ItemStack shop = itemStack.createItemStack(Material.GOLD_INGOT,ChatColor.GOLD + "打开商店",ChatColor.WHITE + "服务器有着不同的商店",ChatColor.WHITE + "打开，你会知道它是什么",ChatColor.WHITE + "嗯哼~",1,false);
                ItemStack head = playerHead.getHead(player,1,false,player.getName(),"无法取得rank信息","请联系管理员","错误代码8217");
                int rankLevel = rank.getRank(player);
                try {
                    if (rankLevel == 0) {
                        head = playerHead.getHead(player,1,false,ChatColor.GRAY + player.getName(),ChatColor.WHITE + "欢迎！亲爱的" + player.getName(),ChatColor.WHITE + "轻触以打开玩家菜单","");
                    }else if (rankLevel == 1) {
                        head = playerHead.getHead(player,1,false,ChatColor.GREEN + "[VIP]" + player.getName(),ChatColor.WHITE + "欢迎！亲爱的" + player.getName(),ChatColor.WHITE + "轻触以打开玩家菜单",ChatColor.GREEN + "您是高贵的铁卡用户");
                    }else if (rankLevel == 2) {
                        head = playerHead.getHead(player,1,false,ChatColor.GREEN + "[VIP+]" + player.getName(),ChatColor.WHITE + "欢迎！亲爱的" + player.getName(),ChatColor.WHITE + "轻触以打开玩家菜单",ChatColor.GREEN + "您是高贵的金卡用户");
                    }else if (rankLevel == 3) {
                        head = playerHead.getHead(player,1,false,ChatColor.AQUA + "[MVP]" + player.getName(),ChatColor.WHITE + "欢迎！亲爱的" + player.getName(),ChatColor.WHITE + "轻触以打开玩家菜单",ChatColor.AQUA + "您是高贵的钻石卡用户");
                    }else if (rankLevel == 4) {
                        head = playerHead.getHead(player,1,false,ChatColor.AQUA + "[MVP+]" + player.getName(),ChatColor.WHITE + "欢迎！亲爱的" + player.getName(),ChatColor.WHITE + "轻触以打开玩家菜单",ChatColor.AQUA + "您是尊贵的Premium用户");
                    }else if (rankLevel == 621) {
                        head = playerHead.getHead(player,1,true,ChatColor.LIGHT_PURPLE + "[Gemini]" + player.getName(),ChatColor.WHITE + "欢迎！亲爱的" + player.getName(),ChatColor.WHITE + "轻触以打开玩家菜单",ChatColor.AQUA + "您是Gemini");
                    }
                }catch (NullPointerException ignore) {
                }
                ItemStack smp = itemStack.createItemStack(Material.GRASS_BLOCK,ChatColor.LIGHT_PURPLE + "星云(starCloud) 联机平台",ChatColor.WHITE + "星云(starCloud) 是一个内嵌于繁星梦服务器的MC联机平台",ChatColor.WHITE + "您可在此创建联机房间，邀请好友一起游玩!",ChatColor.WHITE + "需要至少" + ChatColor.AQUA + "Premium" + ChatColor.WHITE + "权限才能创建房间",1,true);
                Inventory menu = Bukkit.createInventory(player,54,ChatColor.LIGHT_PURPLE + "繁星梦服务器菜单");
                menu.setItem(0,introduce);
                menu.setItem(8,head);
                menu.setItem(10,forNormal);
                menu.setItem(12,kill);
                menu.setItem(13,weather);
                menu.setItem(14,sun);
                menu.setItem(15,randomTP);
                try {
                    if (!player.getDisplayName().contains("免战")) {
                        menu.setItem(16,noWar);
                    }else {
                        ItemStack War = itemStack.createItemStack(Material.RED_BANNER,ChatColor.RED + "关闭免战",ChatColor.WHITE + "点击以切换免战状态。免战状态下，",ChatColor.WHITE + "你无法和玩家对战,其他玩家也无法伤害你。","",1,false);
                        menu.setItem(16,War);
                    }
                }catch (NullPointerException ignore) {
                }
                menu.setItem(19,miniGame);
                menu.setItem(21,bedwar);
                menu.setItem(22,zombies);
                menu.setItem(23,hideAndSeek);
                menu.setItem(28,normalIn);
                menu.setItem(30,normal);
                menu.setItem(31,mod);
                menu.setItem(45,lobby);
                menu.setItem(49,smp);
                menu.setItem(53,tpsBar);
                menu.setItem(51,shop);
                try {
                    if (player.hasPermission("xzrui.menu.op")) {
                        ItemStack gm = new ItemStack(Material.COMMAND_BLOCK);
                        ItemMeta gm_meta = gm.getItemMeta();
                        gm_meta.setDisplayName(ChatColor.LIGHT_PURPLE + "切换创造/生存模式");
                        gm.setItemMeta(gm_meta);
                        menu.setItem(47,gm);
                    }
                }catch (NullPointerException ignore) {
                }
                player.openInventory(menu);
            }else {
                System.out.println("xiaCore | this command can only use by player.");
            }
        }catch (NullPointerException ignore) {
        }
        return false;
    }
}